import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import mint from '@/components/mint-ui'
import toto from '@/components/toto'
import routers from '@/components/router'
import class2 from '@/components/class2'
import error from '@/components/error'
import yjf from '@/components/yjf'
import ys from '@/components/ys'
import dashboard from '@/components/dashboard'
import detail from '@/components/detail'
import joke2 from '@/components/joke'
import subDetail from '@/components/detail2'
import vuex from '@/components/vuex'

Vue.use(Router)

export default new Router({
  routes: [

    {
      //element 
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      // mint-ui
      path: '/mint',
      name: 'mint',
      component: mint,
    },
    {
      // 记事本
      path: '/toto',
      name: 'toto',
      component: toto,
     
    },
    {
      // 动态路由
      path: '/routers/:usname',
      name: 'routers',
      component: routers
    },
    {
      path: '/routers/:usname/about/:id',
      name: 'routers',
      component: routers,
      //修改元信息
      meta:{
        // 1、
        title:'元信息'
      },
       // 单个路由守卫
       beforeEnter:(to,from,next) =>{
        //  2、
        document.title=to.meta.title
        if(localStorage.getItem('name') != 'yjf'){
            alert('禁止入内')
        }
        next()
      }
    },
    // 页面跳转  导入axios工具实现获取后台数据
    {
      path:'/class2',
      name:'class2',
      component:class2,
      children:[
        {
          path:'yjf',
          name:'yjf',
          component:yjf
        },
        {
          path:'ys',
          name:'ys',
          component:ys
        }
      ]
    },
    // 段子列表 和 网易新闻
    {
      path: '/dashboard',
      name: 'dashboard',
      component: dashboard,
     
    },
    // 段子详情页 
    {
      path: '/detail/:sid',
      name: 'detail',
      component: detail,
     
    },
    // 导航切换信息
    {
      path: '/joke2',
      name: 'joke2',
      component: joke2,
      children:[
        {
          path:':sid',
          name:'detail2',
          component:subDetail
        }
      ]
    },
    {
      path: '/vuex',
      name: 'vuex',
      component: vuex,
     
    },
    {
      // 404页面
      path:'*',
      component:error
      // redirect:'mint' 默认跳转
      
    }
  
  ]
  
})
